﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DSS_XNA.Engine.Timer
{
    public class Timer
    {
        #region Properties

        public TimeSpan Time
        {
            get { return _time; }
            set { _time = value; }
        }
        private TimeSpan _time = new TimeSpan();

        public TimerState State
        {
          get { return _state; }
          set { _state = value; }
        }
        private TimerState _state = TimerState.Stopped;

        #endregion

        #region Public Methods

        public Timer()
        {
        }

        public void Run(GameTime gameTime)
        {
            if(this.State != TimerState.Running)
                return;

            this.Time += gameTime.ElapsedGameTime;
        }

        public void Start()
        {
            if (this.State != TimerState.Stopped)
                return;

            this.State = TimerState.Running;
        }

        public void Stop()
        {
            this.State = TimerState.Stopped;
            this.Time = new TimeSpan();
        }

        public void Reset()
        {
            this.Time = new TimeSpan();
        }

        public void Pause()
        {
            this.State = TimerState.Paused;
        }

        public void Resume()
        {
            if (this.State != TimerState.Paused)
                return;

            this.State = TimerState.Running;
        }

        public void Add(TimeSpan toAdd)
        {
            this.Time += toAdd;
        }

        public void Subtract(TimeSpan toSubtract)
        {
            this.Time -= toSubtract;
        }

        #endregion
    }
}
